import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;
import realm.CustromRealm;

public class ReamTest {
    public static void main(String[] args) {
        DefaultSecurityManager sc = new DefaultSecurityManager();

        sc.setRealm(new CustromRealm());

        SecurityUtils.setSecurityManager(sc);

        Subject subject = SecurityUtils.getSubject();

        UsernamePasswordToken token = new UsernamePasswordToken("maomao", "121");

        try {
            subject.login(token);
        } catch (UnknownAccountException e) {
            System.out.println(e);
            System.out.println("用户名错误");
        } catch (IncorrectCredentialsException e) {
            System.out.println(e);
            System.out.println("密码错误");
        }
    }
}
